import{d as Ke,u as Xe,r as f,g as Ye,o as Ze,a as y,c as b,f as _e,b as x,j as w,t as N,h as C,n as D,w as we,v as Se,i as Qe,e as Pe,F as et,p as ke,q as Te,s as tt}from"./entry.5ad382d5.js";import{u as A}from"./v4.8fa37806.js";import{m as Q,R as at,T as j,w as Ie}from"./helpers.e5008248.js";import{_ as rt}from"./MoonLoader.vue_vue_type_script_setup_true_lang.c23528cc.js";import{a as nt,u as ot,S as g,E as M}from"./index.90afdec6.js";import{f as st}from"./funnel_event_helper.bd666bbb.js";import{b as q,g as G,d as H,a as it}from"./Attributions.8b50d119.js";import{F as Ee}from"./FunnelServices.7706eef5.js";import{P as O,c as lt,O as ut}from"./orderform_helpers.f999d6a6.js";import{u as ct}from"./index.aef3f049.js";import{A as ee,N as te}from"./HLConst.6f34af32.js";import"./components.c174aab2.js";import"./composables.beb677dc.js";import"./index.a36dcaca.js";var Oe={exports:{}},ae={};Object.defineProperty(ae,"__esModule",{value:!0});function J(s){return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?J=function(t){return typeof t}:J=function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},J(s)}var Le="https://js.stripe.com/v3",dt=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/,xe="loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used",pt=function(){for(var t=document.querySelectorAll('script[src^="'.concat(Le,'"]')),n=0;n element.");return d.appendChild(l),l},mt=function(t,n){!t||!t._registerWrapper||t._registerWrapper({name:"stripe-js",version:"1.29.0",startTime:n})},z=null,ft=function(t){return z!==null||(z=new Promise(function(n,l){if(typeof window>"u"){n(null);return}if(window.Stripe&&t&&console.warn(xe),window.Stripe){n(window.Stripe);return}try{var d=pt();d&&t?console.warn(xe):d||(d=vt(t)),d.addEventListener("load",function(){window.Stripe?n(window.Stripe):l(new Error("Stripe.js not available"))}),d.addEventListener("error",function(){l(new Error("Failed to load Stripe.js"))})}catch(k){l(k);return}})),z},yt=function(t,n,l){if(t===null)return null;var d=t.apply(void 0,n);return mt(d,l),d},gt=function(t){var n=`invalid load parameters; expected object of shape {advancedFraudSignals: boolean} but received `.concat(JSON.stringify(t),` `);if(t===null||J(t)!=="object")throw new Error(n);if(Object.keys(t).length===1&&typeof t.advancedFraudSignals=="boolean")return t;throw new Error(n)},Re,Ne=!1,Ce=function(){for(var t=arguments.length,n=new Array(t),l=0;lTe(()=>import("./NewPaypalSmartBtnSubscription.fe63ba79.js"),["./NewPaypalSmartBtnSubscription.fe63ba79.js","./paypal-js.67e0b930.js","./index.aef3f049.js","./entry.5ad382d5.js","./entry.e35d8a05.css","./MoonLoader.vue_vue_type_script_setup_true_lang.c23528cc.js","./NewPaypalSmartBtnSubscription.3a186e73.css"],import.meta.url).then(s=>s.default||s)),bt=ke(()=>Te(()=>import("./NewPaypalSmartBtnOrder.bd56c554.js"),["./NewPaypalSmartBtnOrder.bd56c554.js","./paypal-js.67e0b930.js","./index.aef3f049.js","./entry.5ad382d5.js","./entry.e35d8a05.css","./MoonLoader.vue_vue_type_script_setup_true_lang.c23528cc.js","./NewPaypalSmartBtnOrder.3a186e73.css"],import.meta.url).then(s=>s.default||s)),_t=["href","target"],wt={key:0,style:{"margin-right":"5px"},class:"button-icon-start"},St={class:"main-heading-button"},Pt={key:1,style:{"margin-left":"5px"},class:"button-icon-end"},It={class:"sub-heading-button"},Et=["disabled","id"],xt={key:0,class:"button-icon-start"},kt={class:"main-heading-button"},Tt={key:1,class:"button-icon-end"},Ot={class:"sub-heading-button"},Lt={class:"btn-loader-position",style:{left:"50%",position:"absolute",top:"50%",transform:"translate(-50%, -50%)"}},Rt={key:2,style:{width:"70%",margin:"auto"},class:"paypal-content"},Nt={key:3,class:"card-el-error-msg error-message",style:{"justify-content":"center"}},Ct={inheritAttrs:!1},Jt=Ke({...Ct,__name:"Button",props:{element:{type:Object,required:!0},classStyles:{type:Array,required:!0}},setup(s){var ve,me,fe,ye,ge,he,be;const t=s,n=ct(),{openPopup:l}=nt(),{call:d,createMembershipToken:k,mailTo:De,sms:Ae,goToNextFunnelStep:L,openUrl:K,getNextFunnelStepURL:Me}=ot(),Fe=Xe(),{$bus:re}=Fe;let F=(me=(ve=t.element.extra)==null?void 0:ve.text)==null?void 0:me.value;F=Q(F);let U=(ye=(fe=t.element.extra)==null?void 0:fe.subText)==null?void 0:ye.value;U=Q(U);const Ue=n.value.funnelId,$e=n.value.stepId,Be=n.value.funnelPageId,c=n.value.locationId,_=(be=(he=(ge=t.element.extra)==null?void 0:ge.productId)==null?void 0:he.value)==null?void 0:be.id,ne=f("avascript: void(0)"),p=f(!1),oe=f(!1),se=f(""),ie=f(""),X=f(),Y=f(!1),le=f(""),$=f(""),S=f(""),h=f(!1),Ve=Ye(()=>{var e;return((e=X.value)==null?void 0:e.price.type)==="recurring"}),m=f(),v=f("");Ze(()=>{const{action:{value:e}}=t.element.extra;if(e===g.GO_TO_NEXT_STEP||e===g.SELL_PRODUCT){const a=n.value.funnelDomain,r=n.value.funnelNextPageId;a?ne.value=`https://${a}${n.value.funnelNextStep}`:r&&(ne.value=`https://${window.location.host}/v2/preview/${r}`)}(e===g.CLICK_TO_CALL||e===g.CLICK_TO_SMS||e===g.GO_TO_URL||e===g.GO_TO_STEP)&&(oe.value=!0,se.value=ze()),n.value.orderFormVersion===2&&_&&e===g.SELL_PRODUCT&&We()});async function We(){var e,a,r;try{const o=await Ee.findProductById({productId:_});X.value={...o,qty:1,amount:o.price.amount},$.value=(e=o==null?void 0:o.price)==null?void 0:e.currency}catch(o){const i=((r=(a=o==null?void 0:o.response)==null?void 0:a.data)==null?void 0:r.message)||(o==null?void 0:o.message)||"Not able to fetch products!";alert(i)}}async function je(){n.value.videoExistsInPage&&re.$emit("handle-redirect")}async function qe(){const{action:e}=t.element.extra;switch(e.value){case"openPopup":{l();break}case"url":{const{visitWebsite:a}=t.element.extra;K(a.value);break}case"hide-element":{const{hideElements:a}=t.element.extra;at(a.value);break}case"scroll-to-element":{const{scrollToElement:a}=t.element.extra;re.$emit("scroll-to-element",a.value);break}case"go-to-next-funnel-step":{p.value=!0,L();break}case g.GO_TO_STEP:{p.value=!0,L(t.element.extra.stepPath.value);break}case"sell-product":{if(p.value=!0,n.value.orderFormVersion===2)if(A("provider").value==="pp")Y.value=!0;else{if(n.value.defaultPaymentProvider===ee&&n.value.merchantLoginId){ue(ee);return}else if(n.value.defaultPaymentProvider===te&&n.value.nmiMerchantGatewayId){ue(te);return}const a=n.value.stripePublishableKey,r=n.value.stripeAccountId;if(a&&r)le.value=await Oe.exports.loadStripe(a,{stripeAccount:r});else{alert("Stripe account not found!");return}Ge()}else He();break}case"click-to-call":{const a=t.element.extra;d(a[M.PHONE_NUMBER].value);break}case"click-to-sms":{const a=t.element.extra;Ae(a[M.PHONE_NUMBER].value);break}case"click-to-mail":{const a=t.element.extra;De(a[M.EMAIL_ADDRESS].value);break}case g.GO_TO_MEMBERSHIP:{try{let a;const r=n.value.locationId,{ct:o,previewUrl:i}=JSON.parse(decodeURIComponent(A(`_mf_${r}`).value));location.hostname==="localhost"?a=`http://localhost:4040/library/?domain=${i}&token=${o}&location_id=${r}`:a=`${i}/library?&token=${o}&location_id=${r}`,K({url:a,newTab:!1})}catch{alert("Sorry something went wrong.")}break}default:console.error(`Invalid action type received: ${e.value}`)}}function B(e){var a,r;try{const o=e==null?void 0:e.membershipPurchase;o!=null&&o.length&&k(c,o[0].token);const i=e==null?void 0:e.membershipToken;i&&k(c,i),tt(()=>{st("track","Upsell")});const{saleAction:u,stepPath:R,visitWebsite:T}=t.element.extra;if(!u)if(n.value.funnelNextStep){L();return}else throw new Error("Redirect not handled");if(n.value.orderFormVersion===2){const P=`_pl_${n.value.funnelId}`,I=localStorage.getItem(P);if(I){let E=JSON.parse(I);E.push(X.value),Ie(P,JSON.stringify(E))}}else{const P=`_pl_v1_${n.value.funnelId}`,I=localStorage.getItem(P);if(I){let E=JSON.parse(I);E.push((r=(a=t==null?void 0:t.element.extra)==null?void 0:a.productId)==null?void 0:r.value),Ie(P,JSON.stringify(E))}}switch(u.value){case"url":if(T&&T.value&&T.value.url){K(T.value);break}else throw new Error("Redirect not handled");case"step-path":if(R&&R.value){L(R.value);break}else throw new Error("Redirect not handled");default:if(n.value.funnelNextStep){L();break}else throw new Error("Redirect not handled")}}catch{alert(`Order successfully placed! However, Something went wrong while displaying this webpage, please contact the seller.`),p.value=!1;return}}const Z=async()=>{var r;let e=localStorage.getItem("_ud");e&&(e=JSON.parse(e));const a=e==null?void 0:e.customer_id;if(!a){v.value="Contact not found!";return}if(m.value=await lt({contactId:a,domain:n.value.domain,pageUrl:n.value.pageUrl,locationId:c,productPreviewList:[{_id:_,qty:1}],store:n.value,subType:ut.UPSELL,traceId:e==null?void 0:e.traceId}),(r=m.value)!=null&&r.error){h.value=!1;return}};async function Ge(){var e;try{if(!_)throw new Error("No product Id found for initiating stripe payment");if(v.value="",await Z(),!m.value||((e=m.value)==null?void 0:e.error))return;const a={altId:c,altType:"location",orderId:m.value.order._id},r=await O.initiateStripePayment(a);if(!r.success){v.value=r.message||"We're sorry, but something went wrong. Please try again.";return}const{clientSecret:o,paymentMethodId:i}=r;if(o){const W=await le.value.confirmCardPayment(o,{payment_method:i,setup_future_usage:"off_session"});if(W.error){console.error("Failed to confirm card payment!",W.error),W.error.message&&alert(W.error.message);return}}const{orderId:u,paymentIntentId:R,subscriptionId:T,invoiceId:P,subId:I,txnId:E}=r,Je={altId:c,altType:"location",orderId:u,paymentIntentId:R,subscriptionId:T,invoiceId:P,isAuth:!1,subId:I,txnId:E,attribution:{eventData:q(),sessionId:G(c),sessionFingerprint:H(c)}},V=await O.verifyStripePayment(Je);if(console.log("verifyPaymentResponseData",V),!V.success){v.value=V.message||"We're sorry, but something went wrong. Please try again.";return}await B(V)}catch(a){v.value=j(a),p.value=!1,console.error(a)}}async function ue(e){var a,r,o;try{if(!_)throw new Error("No product Id found for initiating stripe payment");if(h.value=!0,v.value="",await Z(),!m.value||((a=m.value)==null?void 0:a.error))return;let i;if((r=m.value)!=null&&r.order._id){i={altId:c,altType:"location",orderId:(o=m.value)==null?void 0:o.order._id,attribution:{eventData:q(),sessionId:G(c),sessionFingerprint:H(c)}};let u;switch(e){case ee:{u=await O.authorizeNetOrderPayment(i);break}case te:{u=await O.nmiOrderPayment(i);break}default:console.log("Invalid payment provider");break}if(console.log(u),h.value=!1,!u.success){v.value=u.message||"We're sorry, but something went wrong. Please try again.";return}await B({membershipPurchase:u.membershipPurchase,membershipToken:u.membershipToken})}}catch(i){p.value=!1,h.value=!1,console.log(i),v.value=j(i)}}async function He(){if(!!_)try{const e=it(),a={...q(),fbEventId:e},r=G(c),o=H(c),i=await Ee.funnelPayment({fingerprint:A("msgsndr_id").value,productList:[_],locationId:c,funnelId:Ue,stepId:$e,pageId:Be,domain:n.value.domain,pageUrl:n.value.pageUrl,source:"payment_button",submissionType:3,eventData:a,sessionId:r,sessionFingerprint:o,_mp:A("_mp").value});await B(i)}catch(e){console.log(e)}finally{p.value=!0}}async function ce(e,a){var r,o;try{if(!_)throw new Error("No product Id found for initiating paypal payment");if(h.value=!0,S.value="",v.value="",await Z(),!m.value||((r=m.value)==null?void 0:r.error))return;const i={altId:c,altType:"location",orderId:(o=m.value)==null?void 0:o.order._id},u=await O.initiatePayPalPayment(i);if(!u.success){v.value=u.message||"We're sorry, but something went wrong. Please try again.";return}if(a.subscription&&u.plan_id)return a.subscription.create(u);if(a.order&&u.id)return u.id}catch(i){console.log(i.message),S.value=j(i),h.value=!1}}async function de(e){try{if(!_)throw new Error("No product Id found for paypal payment");h.value=!0,S.value="",v.value="";const a={facilitatorAccessToken:e.facilitatorAccessToken,orderId:m.value.order._id,paypalOrderId:e.orderID,altId:c,altType:"location",attribution:{eventData:q(),sessionId:G(c),sessionFingerprint:H(c)}};e.payerID&&(a.paypalPayerId=e.payerID),e.subscriptionID&&(a.paypalSubscriptionId=e.subscriptionID);const r=await O.verifyPayPalPayment(a);if(console.log("verifyPaymentResponseData",r),!r.success){v.value=r.message||"We're sorry, but something went wrong. Please try again.";return}const o=A("provider");o.value="pp",await B(r)}catch(a){console.error(a.message),S.value=j(a),h.value=!1}}function pe(){h.value=!1,S.value="Transaction has been cancelled by the user!"}function ze(){let e="";const{action:{value:a}}=t.element.extra;switch(a){case g.CLICK_TO_CALL:{let r=t.element.extra[M.PHONE_NUMBER].value;r=r.replace("tel:",""),e=`tel:${r}`;break}case g.CLICK_TO_SMS:{let r=t.element.extra[M.PHONE_NUMBER].value;r=r.replace("sms:",""),e=`sms:${r}`;break}case g.GO_TO_URL:{const{visitWebsite:{value:r}}=t.element.extra,{url:o,newTab:i}=r;e=o,e=Q(e),e&&!e.startsWith("#")&&!/^https?:/.test(e)&&(e=`https://${e}`),ie.value=i?"_blank":"";break}case g.GO_TO_STEP:{const r=t.element.extra.stepPath.value;e=Me(r);break}}return e}return(e,a)=>{const r=ht,o=bt;return y(),b(et,null,[oe.value?(y(),b("a",{key:0,href:se.value,target:ie.value,class:_e(s.classStyles),onClick:je},[x("span",{style:D(p.value?"visibility: hidden;":""),class:"main-heading-group"},[s.element.extra.icon!==""?(y(),b("span",wt)):w("",!0),x("span",St,N(C(F)),1),s.element.extra.icon!==""?(y(),b("span",Pt)):w("",!0)],4),s.element.extra.subText&&s.element.extra.subText.value?(y(),b("span",{key:0,style:D(p.value?"visibility: hidden;":""),class:"sub-heading-group text-xs font-sans"},[x("span",It,N(C(U)),1)],4)):w("",!0)],10,_t)):we((y(),b("button",{key:1,disabled:p.value,id:s.element.id,style:D(p.value?"cursor: default;":""),class:_e([s.classStyles]),onClick:qe},[x("div",{style:D(p.value?"visibility: hidden;":""),class:"main-heading-group"},[s.element.extra.icon!==""?(y(),b("div",xt)):w("",!0),x("div",kt,N(C(F)),1),s.element.extra.icon!==""?(y(),b("div",Tt)):w("",!0)],4),s.element.extra.subText&&s.element.extra.subText.value?(y(),b("div",{key:0,style:D(p.value?"visibility: hidden;":""),class:"text-xs font-sans"},[x("div",Ot,N(C(U)),1)],4)):w("",!0),we(x("div",Lt,[Qe(rt,{loading:p.value,color:"rgb(255, 255, 255)",size:"30px"},null,8,["loading"])],512),[[Se,p.value]])],14,Et)),[[Se,!Y.value]]),Y.value&&$.value?(y(),b("div",Rt,[C(Ve)?(y(),Pe(r,{key:0,initiatePaypalPayment:ce,onApprovePaypalPayment:de,onCancelPaypalPayment:pe,paypalErrorMsg:S.value,processingPayment:h.value,currency:$.value},null,8,["paypalErrorMsg","processingPayment","currency"])):(y(),Pe(o,{key:1,initiatePaypalPayment:ce,onApprovePaypalPayment:de,onCancelPaypalPayment:pe,paypalErrorMsg:S.value,processingPayment:h.value,currency:$.value},null,8,["paypalErrorMsg","processingPayment","currency"]))])):w("",!0),v.value?(y(),b("div",Nt,N(v.value),1)):w("",!0)],64)}}});export{Jt as default};